package com.ruix.app.mapper;

import com.ruix.app.model.FeedbackAdvice;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/4/29.
 */

public class FeedbackListMapper  implements ApiMapper<ArrayList<FeedbackAdvice>>{
    @Override
    public ArrayList<FeedbackAdvice> transform(JSONObject response) {
        ArrayList feedbacklList = new ArrayList();
        JSONObject data = response.optJSONObject("data");
        if (data != null) {
            JSONArray feedbackList = data.optJSONArray("list");
            if (feedbackList != null && feedbackList.length() > 0){
                 for (int i = 0;i<feedbackList.length();i++){
                     FeedbackAdvice advice = new FeedbackAdvice().parse(feedbackList.optJSONObject(i));
                     feedbacklList.add(advice);

                 }
            }
        }
        return feedbacklList;
    }
}
